#ifndef HEAPSORT
#define HEAPSORT


#include <iostream>

//堆排序.
/*
  堆实际上是一棵完全二叉树，其任何一非叶节点满足性质：

  Key[i]<=key[2i+1]&&Key[i]<=key[2i+2]或者Key[i]>=Key[2i+1]&&key>=key[2i+2]

  即任何一非叶节点的关键字不大于或者不小于其左右孩子节点的关键字。
 */
class HeapSort
{
public:
	HeapSort(int * array, int len);
	
	void Swap(int index1, int index2);
	void Print(int eleCount = 0);
	//void MaxHeapify(int maxHeapIndex);
	void MaxHeapify(int lastParentIndex, int maxIndex);
	void CreateHeap();
	void SortHeap();



private:
	int * m_array;
	int m_len;
};

#endif
